//
//  XMPWSetViewController.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/3.
//

#import "XMPWSetViewController.h"
#import "XMPWSetView.h"
#import "XMNetwork+login.h"
#import "XMNetwork+mine.h"

@interface XMPWSetViewController ()

@end

@implementation XMPWSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    XMPWSetView *pwSetView = [[XMPWSetView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:pwSetView];
    XMWeakSelf;
    pwSetView.getCodeBlock = ^{
        [weakSelf getCode];
    };
    pwSetView.commitBlock = ^(NSString * _Nonnull codeStr, NSString * _Nonnull pwStr) {
        [weakSelf pwSetWithPW:pwStr code:codeStr];
    };
    
}

- (void)getCode {
    [_Network getCodeWithPhoneNum:_userInfoModel.mobile
                             type:@"3"
                          success:^(id  _Nonnull responseObject) {
        [MBProgressHUD showSuccess:@"发送成功"];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

- (void)pwSetWithPW:(NSString *)newPw code:(NSString *)codeStr {
    XMWeakSelf;
    [_Network pwSetWithNewPW:newPw
                        code:codeStr
                     success:^(id  _Nonnull responseObject) {
        [MBProgressHUD showSuccess:@"修改成功"];
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
